package com.hjm.project.frozenAgent.controller;

import java.util.List;
import java.util.Map;

import com.hjm.project.frozenAgent.service.IFrozenAgentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.frozenAgent.domain.FrozenAgent;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 代理商冻结Controller
 * 
 * @author maker-platform
 * @date 2021-04-23
 */
@Controller
@RequestMapping("/frozenAgent/frozenAgent")
public class FrozenAgentController extends BaseController
{
    private String prefix = "frozenAgent";

    @Resource
    private IFrozenAgentService frozenAgentService;

    @RequiresPermissions("frozenAgent:frozenAgent:view")
    @GetMapping()
    public String frozenAgent()
    {
        return prefix + "/frozenAgent";
    }

    /**
     * 查询代理商冻结列表
     */
    @RequiresPermissions("frozenAgent:frozenAgent:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FrozenAgent frozenAgent)
    {
        startPage();
        List<FrozenAgent> list = frozenAgentService.selectFrozenAgentList(frozenAgent);
        return getDataTable(list);
    }

    /**
     * 导出代理商冻结列表
     */
    @RequiresPermissions("frozenAgent:frozenAgent:export")
    @Log(title = "代理商冻结", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FrozenAgent frozenAgent)
    {
        List<FrozenAgent> list = frozenAgentService.selectFrozenAgentList(frozenAgent);
        ExcelUtil<FrozenAgent> util = new ExcelUtil<FrozenAgent>(FrozenAgent.class);
        return util.exportExcel(list, "frozenAgent");
    }

    /**
     * 新增代理商冻结
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代理商冻结
     */
    @RequiresPermissions("frozenAgent:frozenAgent:add")
    @Log(title = "代理商冻结", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FrozenAgent frozenAgent, @RequestParam Map<String,String> params)
    {
        frozenAgent.setAgentNum(params.get("leaderAgentNum"));
        return toAjax(frozenAgentService.insertFrozenAgent(frozenAgent));
    }

    /**
     * 修改代理商冻结
     */
    @GetMapping("/edit/{agentNum}")
    public String edit(@PathVariable("agentNum") String agentNum, ModelMap mmap)
    {
        FrozenAgent frozenAgent = frozenAgentService.selectFrozenAgentById(agentNum);
        mmap.put("frozenAgent", frozenAgent);
        return prefix + "/edit";
    }

    /**
     * 修改保存代理商冻结
     */
    @RequiresPermissions("frozenAgent:frozenAgent:edit")
    @Log(title = "添加冻结服务商", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FrozenAgent frozenAgent)
    {
        return toAjax(frozenAgentService.updateFrozenAgent(frozenAgent));
    }

    /**
     * 删除代理商冻结
     */
    @RequiresPermissions("frozenAgent:frozenAgent:remove")
    @Log(title = "删除冻结服务商", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(frozenAgentService.deleteFrozenAgentByIds(ids));
    }
}
